<?php defined('BASEPATH') OR exit('No direct script access allowed');
/**
 * Admin controller for the users module
 *
 * @author 		Phil Sturgeon - PyroCMS Dev Team
 * @package 	PyroCMS
 * @subpackage 	Users module
 * @category	Modules
 */
class Admin extends Admin_Controller
{
	/**
	 * Validation array
	 * @access private
	 * @var array
	 */
	private $validation_rules = array();

	/**
	 * Constructor method
	 * @access public
	 * @return void
	 */
	public function __construct()
	{
		
		// Call the parent's constructor method
		parent::Admin_Controller();

		// Load the required classes
		$this->load->model('user_m');
		$this->load->library('form_validation');

	}

	/**
	 * List all users
	 * @access public
	 * @return void
	 */
	public function index()
	{
	}
	
	function profile()
	{
		$user_info = $this->user_m->get(1);
		
		$this->form_validation->set_rules('username', '管理员名字', 'required|max_length[60]|xss_clean');
		$this->form_validation->set_rules('password', '管理员密码', 'max_length[10]|xss_clean');
			
		if ($this->form_validation->run() == TRUE)
		{
			$username = $this->input->post('username');
			$password = $this->input->post('password');
			
			$update_ary = array();
			if(FALSE != $username)
			{
				$update_ary['username'] = $username;
			}
			if(FALSE != $password)
			{
				$update_ary['password'] = authcode($password,'ENCODE');
			}
			
			$this->user_m->update($user_info->id, $update_ary, TRUE);
			$this->session->set_flashdata('success', '资料成功更新');

			redirect('admin/users/profile', 'refresh');
		}
		$this->template
			->set('user_info', $user_info)
			->build('admin/profile');
	}
}
?>
